# Contributor (MSYS2): David Macek <david.macek.0@gmail.com>
# Maintainer (Arch Linux): Kyle Keen <keenerd@gmail.com>
# Maintainer (Arch Linux): Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor (Arch Linux): Geoffroy Carrier <geoffroy.carrier@koon.fr>
# Contributor (Arch Linux): arjan <arjan@archlinux.org>
# Contributor (Arch Linux): Tom Newsom <Jeepster@gmx.co.uk>

_realname=ucl
pkgname=("ucl" "ucl-devel")
pkgver=1.03
pkgrel=2
pkgdesc="Portable lossless data compression library written in ANSI C"
arch=('i686' 'x86_64')
license=('GPL')
url="https://www.oberhumer.com/opensource/ucl/"
source=("https://www.oberhumer.com/opensource/${_realname}/download/${_realname}-${pkgver}.tar.gz"
        "000-msys2.patch"
        "001-autoconf-compat.patch"
        "002-missing-macros.patch"
        "003-no-undefined.patch")
sha256sums=('b865299ffd45d73412293369c9754b07637680e5c826915f097577cd27350348'
            '46434a4cc85a35d04391745fa7cd317646bf883df7d220256597e7113b4f7497'
            '0cbd00a8383c098f98d5b022fcb4fa8d1448501e00221a223be04be0383bafc0'
            'ed5425536d98e2097488001e6e73d2ed93da65050a6fded62435bec077bc594b'
            '56a110aedab800c0a06cf4fd4dcef8f78691a0d091e2f143a2a8f02cfbb4c172')

prepare() {
  cd "${_realname}-${pkgver}"
  rm -f acinclude.m4
  patch -p1 -i "${srcdir}/000-msys2.patch"
  patch -p1 -i "${srcdir}/001-autoconf-compat.patch"
  patch -p1 -i "${srcdir}/002-missing-macros.patch"
  patch -p1 -i "${srcdir}/003-no-undefined.patch"

  touch ChangeLog
  WANT_AUTOMAKE=latest autoreconf -fiv
}

build() {
  cd "${_realname}-${pkgver}"
  
  CPPFLAGS="$CPPFLAGS -std=c90 -fPIC" \
  ./configure \
    --build=${CHOST} \
    --prefix=/usr \
    --enable-shared \
    --enable-static \
    --disable-asm

  make
  make DESTDIR=${srcdir}/dest install
}

package_ucl() {
  mkdir -p ${pkgdir}/usr
  cp -rf ${srcdir}/dest/usr/bin ${pkgdir}/usr/
  
  install -Dm644 "${srcdir}/${pkgname}-${pkgver}/COPYING" "${pkgdir}/usr/share/licenses/${pkgname}/COPYING"
}

package_ucl-devel() {
  groups=('development')
  options=(staticlibs)
  depends=("ucl=${pkgver}")
  pkgdesc="ucl headers and libraries"

  mkdir -p ${pkgdir}/usr
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib ${pkgdir}/usr/
}
